/*
* ============================================================================
* 功能描述 ：应用层配置
* 作者       ：ggls
* 创建日期 ：2024.04.10
* ----------------------------------------------------------------------------
* 更新历史 ：
*	日期 　　- 修改者   : 更新内容描述
*
* ============================================================================
*/

#include "main.h"
#include <stdio.h>

static int _temp_lcd(int d)
{
	switch(d)
		{
		   case 1:
			   return 11;
			   break;
		   case 2:
			   return 189;
			   break;
		   case 3:
			   return 159;
			   break;
		   case 4:
			   return 79;
			   break;
		   case 5:
			   return 215;

			   break;
		   case 6:
			   return 247;

			   break;
		   case 7:
			   return 139;

			   break;
		   case 8:
			   return 255;

			   break;
		   case 9:
			   return 223;

			   break;
		   case 0:
			   return 251;

			   break;
		   default:
			   break;

		}

}


static void _zigbee_ready_handle(void)
{
	char aka[3];
	aka[0] = 6;
	aka[1] = 6;
	aka[2] = 6;
	
	Uart_Tx_buf(aka, 3);	
}

static void _temp_handle(signed short t, signed short h)
{
	int t10, t100, t1000;
	int t_10, t_100, t_1000;
	int h10, h100, h1000;
	int h_10, h_100, h_1000;
	char hp[6],c;

	t10 	= t/10%10;		// 十位位
	t100 	= t/100%10;		// 百位
	t1000 	= t/1000;			// 千位
	t_10 	= _temp_lcd(t10);
	t_100 	= _temp_lcd(t100);
	t_1000 	= _temp_lcd(t1000);


	h10 	= h/10%10;		// 十位位
	h100	= h/100%10; 	// 百位
	h1000	= h/1000;			// 千位
	h_10	= _temp_lcd(h10);
	h_100	= _temp_lcd(h100);
	h_1000	= _temp_lcd(h1000);

	hp[0] = SHORT_GET_HIGH_BYTE(h_10);
	hp[1] = SHORT_GET_LOW_BYTE(h_10);
	hp[2] = SHORT_GET_HIGH_BYTE(h_100);
	hp[3] = SHORT_GET_LOW_BYTE(h_100);
	hp[4] = SHORT_GET_HIGH_BYTE(h_1000);
	hp[5] = SHORT_GET_LOW_BYTE(h_1000);

	if((t > 18 || t <= 28) && (h >40 || h <= 65))
	{
		t_10 =t_10 - 1;
	}
	else
	{

	}
#if 0	
	char a1[1],a2[1],a3[1];
	a1[0] = digit100;
	a2[0] = digit10;
	a3[0] = digit1000;
	DelayXms(200);
	Uart_Tx_buf(a1, 1);
	DelayXms(200);
	Uart_Tx_buf(a2, 1);
	DelayXms(200);
	Uart_Tx_buf(a3, 1);
#endif
	Lcd_Set_temp(t_1000, t_100, t_10);

}

void Hly_Temp_Hum_Obtain(void)
{	
	unsigned char Data_f;
	int i;
	unsigned char temp[2], hum[2];
	signed short t,h;
	for(i = 1; i < 10; i++)
	{
		SHT4XReadTemperatureAndHumidity(&t, &h);
	}
	Data_f = SHT4XReadTemperatureAndHumidity(&t, &h);
	if(Data_f == 1)
	{
		Hly_zigbee_up_temp(t);
		DelayXms(2);
		Hly_zigbee_up_hum(h);
		DelayXms(2);
		_temp_handle(t, h);
		temp[0]  =  SHORT_GET_HIGH_BYTE(t);
		temp[1]  =  SHORT_GET_LOW_BYTE(t);

		hum[0]	=  SHORT_GET_HIGH_BYTE(h);
		hum[1]	=  SHORT_GET_LOW_BYTE(h);
		
		//DelayXms(200);
		//Uart_Tx_buf(temp,2);
		//Uart_Tx_buf(hum,2);
		
	}	

}

void app_init(void)
{

	Zigbee_Cmd_handle();
	Zigbee_Config_Set();

}

